import 'package:flutter/material.dart';
import 'package:x3_base_core/x3_base_core.dart';
import 'package:x3_component_core/components/base_components/base_scan_state.dart';

class BaseScan extends StatefulWidget {

  // 扫码的回调事件
  final Function( String value ) callBack;

  // 自定义扫码按钮的点击事件
  final Function customPress;

  // 构造函数
  const BaseScan({ Key key, @required this.callBack, @required this.customPress }) : super(key: key);

  @override
  _BaseScanState createState() => _BaseScanState();

}

class _BaseScanState extends State<BaseScan> with BaseScanState<BaseScan> {

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Container(alignment: Alignment.center, width: 28, height: 36, child: Icon(BaseIconData.x3Scan, color: Colors.grey, size: 18)),
      onTap: widget.customPress != null ? widget.customPress : startScan,
    );
  }

  @override
  void listenScanResult(String value) {
    widget.callBack( value );
  }

}
